home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / infosearch.idb / usr / lib / infosearch / bin / sgindexAdmin.z / sgindexAdmin
Text File  |  2002-10-15  |  22KB  |  892 lines

  1. #!/usr/bin/perl
  2. #
  3. # Copyright 1996-2002, Silicon Graphics, Inc.
  4. # All Rights Reserved.
  5. #
  6. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  7. # the contents of this file may not be disclosed to third parties, copied or
  8. # duplicated in any form, in whole or in part, without the prior written
  9. # permission of Silicon Graphics, Inc.
  10. #
  11. # RESTRICTED RIGHTS LEGEND:
  12. # Use, duplication or disclosure by the Government is subject to restrictions
  13. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  14. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  15. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  16. # rights reserved under the Copyright Laws of the United States.
  17. #
  18. # requires perl5
  19. #
  20. # ------------
  21. # sgindexAdmin
  22. # ------------
  23. #
  24. # see man sgindexAdmin(1)
  25. #
  26. # Manages merging and synchronization of infosearch fulltext 
  27. # indices and creation of tables of contents.
  28. #
  29. # sgindexAdmin -toc    <optional content domain name>
  30. #
  31. #            Create HTML table of contents
  32. #            from the fulltext index title files.
  33. #
  34. # sgindexAdmin -update  <optional content domain name>
  35. #
  36. #                Normally run as an exitop; updates database(s)
  37. #            Also performs the "-toc" phase
  38. #
  39. # sgindexAdmin -instchk <optional content domain name>
  40. #
  41. #                       Same as update, except we just check
  42. #                       the indices dates vs. the inst history
  43. #                       files to see if new products have been
  44. #                       installed. Invoked from /etc/init.d/configmsg
  45. #                       If new products have been installed, run update.
  46. #                Also updates the man whatis database from our
  47. #                man title file.
  48. #
  49. # sgindexAdmin -clean  <optional content domain name>
  50. #            
  51. #            Remove local index & table of 
  52. #            contents (run as a removeop).
  53. #
  54.  
  55. require 5;
  56.  
  57. #----------------------------
  58. # initialize global variables
  59. #
  60. umask 022;
  61. @domainList    = ();
  62. %tocProgramList    = ();
  63. %domainPathList    = ();
  64. %searchPath    = ();
  65. %altProg    = ();
  66. %indexProg    = ();
  67. %contentExpr    = ();
  68.  
  69. $ENV{'SGINDEXADMIN'} = "TRUE";
  70. $tmpdir = $ENV{'TMPDIR'} || "/tmp";
  71.  
  72. $root       = "/";          # -r domain root | $root="/disk2" 
  73. $verbose    = 0;            # -v 
  74. $nfs        = "-local";     # -nfs
  75. $force      = 0;            # -force
  76. $instchk    = 0;        # -instchk
  77. $output     = ">/dev/null"; # set to NULL if $verbose==1
  78. $timex      = "";           # set to "timex" if -t
  79. $keepwrd    = 0;            # delete wrd file when done?
  80. $clean_info = 0;        # remove some op files
  81.  
  82.  
  83. #--------------------------------------------
  84. # add a -r -root to override default settings
  85. #
  86. @TMP = @ARGV;
  87. while ($arg = shift(@TMP)) {
  88.    if ($arg eq "-r") {
  89.       $root = shift(@TMP);
  90.    }
  91. }
  92.  
  93. &readConfig();
  94.  
  95. #-------------------------
  96. # no args, print usage msg
  97. #
  98. if ($#ARGV == -1) {
  99.     &usage();
  100.     exit(1);
  101. }
  102.  
  103. #-----------------------------------------------------------
  104. # clean up tmp files if the program is interrupted or killed
  105. #
  106. $SIG{'INT'}  = 'tmpFileCleanup';
  107. $SIG{'QUIT'} = 'tmpFileCleanup';
  108. $SIG{'KILL'} = 'tmpFileCleanup';
  109. $SIG{'ABRT'} = 'tmpFileCleanup';
  110.  
  111.  
  112. #----------------------
  113. # examine cmd line args
  114. #
  115. while($arg = shift(@ARGV)){
  116.  
  117.     if ($arg eq "-v") {            # verbose mode
  118.     $verbose = 1;
  119.     $output  = "";
  120.     } elsif ($arg eq "-t") {        # report timing stats
  121.     $timex = "timex";
  122.     } elsif ($arg eq "-nfs") {        # remove -local arg from find
  123.     $nfs = "";
  124.     } elsif ($arg eq "-force") {    # force creation of database(s)
  125.     $force = 1;
  126.     } elsif ($arg eq "-r") {        # database(s) root; already handled
  127.         shift(@ARGV);
  128.     } elsif ($arg eq "-missing") {    # no-op; just use -update
  129.         ;
  130.     } elsif ($arg eq "-extra") {    # no-op; just use -update
  131.      ;    
  132.     } elsif ($arg eq "-toc") {        # create browsable files for db
  133.     &makeDomainTOC(shift(@ARGV));
  134.     } elsif ($arg eq "-update") {    # perform database update
  135.     $nextarg = shift(@ARGV);
  136.     &updateDomainIndex($nextarg);
  137.     } elsif ($arg eq "-instchk") {    # perform database update (check inst)
  138.         $instchk = 1;
  139.         &instChkDomainUpdate(shift(@ARGV));
  140.     } elsif ($arg eq "-clean") {    # clean up non-inst local files: exito
  141.         $clean_info = 1;
  142.     &cleanDomainIndex(shift(@ARGV));
  143.     } elsif ($arg eq "-check") {    # no-op
  144.     ;
  145.     } elsif ($arg eq "-keepwrd") {
  146.         $keepwrd = 1;
  147.     } else {
  148.     &usage();
  149.     exit(1);
  150.     }
  151. }
  152.  
  153. &tmpFileCleanup();
  154. exit(0);
  155.  
  156.  
  157.  
  158. #------
  159. # usage
  160. #
  161. sub usage {
  162.     print "Usage:\n\tsgindexAdmin -update {[bks | relnotes | man]}\n";
  163. }
  164.  
  165.  
  166. #-----------
  167. # readConfig
  168. #
  169. sub readConfig {
  170.  
  171.     my($domain) = "";
  172.     my($var,$value) = "";
  173.      
  174.     # no root, so check the value of infosrch.cfg for collection path
  175.     #
  176.     &readISConfig();
  177.  
  178.     while(<DATA>){
  179.  
  180.     next if /^\#/;     # Skip comments
  181.     next if /^$/;   # Skip blank lines
  182.     
  183.     if(/\s*([A-Z]+)\s*=\s*([^\#\n]+)/){
  184.  
  185.         $var   = $1;
  186.         $value = $2;
  187.         $value =~ s/\s+$//; # Remove trailing spaces
  188.         
  189.         if($var eq "DOMAIN"){
  190.         push(@domainList, $value);
  191.         $domain=$value;
  192.         }elsif($var eq "TOCPROG")  {
  193.         $tocProgramList{"$domain"}=$value;
  194.         }elsif($var eq "IDXPROG")  {
  195.         $indexProg{"$domain"}=$value;
  196.         }elsif($var eq "ALTPROG")  {
  197.         $altProg{"$domain"}=$value;
  198.         }elsif($var eq "INFOPATH")  {
  199.         if($value=~/\$([A-Z]+)\s+else\s+(.+)/){
  200.             my($envpath)=$1;
  201.             my($fbpath)=$2;
  202.             unless($ENV{$envpath}){
  203.             @searchPath=split(/\s+/, $fbpath);
  204.             }else{
  205.             @searchPath=split(/:/, $ENV{$envpath});
  206.             }
  207.         }else{
  208.             @searchPath=split(/\s+/, $value);
  209.         }
  210.         my($goodPath) = "";
  211.         foreach (@searchPath){
  212.             my($indexdir) = "";
  213.  
  214.             # The domain Doc Root is prepended to the 
  215.             # ENV SEARCH PATH
  216.             # Only add dirs which exist (else find(1) error)
  217.           
  218.             if (-e &redirectedPath($_)) {
  219.                         $tmpPath = &redirectedPath($_);
  220.                         if (checkPath($tmpPath) == 1) {
  221.                 $goodPath = "$goodPath " . $tmpPath;
  222.                 unless($domainPathList{"$domain"}){
  223.                     $indexdir = $tmpPath . "/SGIindex";
  224.  
  225.                 # If the index dir doesn't exist, create it.
  226.                 # Otherwise, database gets built in "/"
  227.                 #
  228.                 if (!(-e $indexdir)
  229.                                       && 
  230.                     !(mkdir($indexdir, 0755)) ) {
  231.                                       die "mkdir ($indexdir) failed: $!\n";
  232.                 }
  233.                     if (-w $indexdir ){
  234.                     $domainPathList{"$domain"}=$indexdir;
  235.                     }
  236.                 }
  237.             }
  238.             }
  239.         }
  240.         $searchPath{"$domain"} = $goodPath;  
  241.         }elsif($var eq "INFOREGEX")  {
  242.         $contentExpr{"$domain"}=$value;
  243.         }else{
  244.         # skip it;
  245.         }
  246.     }
  247.     }
  248.     close(DATA);
  249. }
  250.  
  251.  
  252. #-------------
  253. # readISConfig
  254. #
  255. #  - parse cfg file
  256. #  - set $root if it's not already set
  257. #  - set collection id
  258. #
  259. sub readISConfig {
  260.  
  261.   my($cfg) = "/usr/lib/infosearch/C/infosrch.cfg";
  262.   open(CFG, "$cfg") or return;
  263.  
  264.   while (<CFG>) {
  265.     if (/\<COLLECTION(.*)\>/) {
  266.       $title, $path, $id = undef;
  267.       $title = $1 if (/TITLE\w*=\w*"([^"]+)"/);
  268.       $path = $1 if (/PATH\w*=\w*"([^"]+)"/);
  269.       $id = $1 if (/ID\w*=\w*"([^"]+)"/);
  270.       # store title, path and collection
  271.       push @cfgtitle, $title;
  272.       push @cfgpath, $path;
  273.       push @cfgid, $id;
  274.     }
  275.   }
  276.   close(CFG);
  277.  
  278.   # $root is first PATH in cfg unless it's been defined
  279.   #
  280.   $root = $cfgpath[0] if ($root ne "/");
  281.  
  282.   # find collection id for this $root
  283.   #
  284.   undef $coll;
  285.   ($dev, $ino) = stat($root) or return;
  286.   for (my($n) = 0; n <= $#cfgtitle; $n++) {
  287.       ($d, $i) = stat $cfgpath[$n] or return;
  288.       if ($dev == $d && $ino == $i) {
  289.          $coll = $cfgid[$n];
  290.          return;
  291.       }
  292.   }
  293. }
  294.  
  295.  
  296. #-------------------------------------------------
  297. # updateDomainIndex($domain) # All if $domain=NULL
  298. #
  299. sub updateDomainIndex {
  300.  
  301.     my($arg) = @_;
  302.     if ($arg eq '') {
  303.         foreach $domain (@domainList){
  304.             &updateIndex($domain);
  305.         }
  306.     } else {
  307.         &updateIndex($arg);
  308.     }
  309. }
  310.  
  311.  
  312. #---------------------
  313. # updateIndex($domain)
  314. #
  315. sub updateIndex {
  316.  
  317.     my($domain) = @_;
  318.     my($do_toc) = 0;
  319.  
  320.     if ($force == 1) {
  321.         $do_toc = 1;
  322.     }
  323.  
  324.     # check to see if we can write to this area
  325.     #
  326.     my($domain_p) = "$domainPathList{$domain}" . "/";
  327.     if ($domainPathList{$domain} eq '' || !(-d $domain_p) || !(-w $domain_p)) {
  328.         if($verbose == 1) {
  329.           print "Cannot write to designated area for $domain: $domain_p \n";
  330.         }
  331.         return;
  332.     }
  333.  
  334.     my($domain_ttl) = &domain2title($domain);
  335.     my($domain_dct) = "$domainPathList{$domain}/$domain.dct";
  336.  
  337.     # set this flag (file) when an operation should not be interrupted.
  338.     # Such ops, if interrupted, could ruin the integrity of the database;
  339.     # use this flag with caution.
  340.     #
  341.     $op_info = "$domainPathList{$domain}/_indexing";
  342.  
  343.     # if this file currently exists, the integrity of our database
  344.     # may have been violated. In such a case, delete the master
  345.     # and the local and begin FROM SCRATCH...
  346.     #
  347.     if(-e $op_info) {
  348.  
  349.         # inform if verbose or in instchk mode (to syslog)
  350.         # 
  351.         if($verbose == 1) {
  352.             print "Building $domain from scratch; this may take a while\n";
  353.         } else {
  354.             if($instchk == 1) {
  355.             $msg = "Building $domain from scratch; this may take a while";
  356.         system("logger -t sgindexAdmin \"$msg\"");        
  357.                 die "logger failed: $!\n" if ($?);
  358.             }
  359.         }
  360.  
  361.         $force = 1;
  362.     }
  363.  
  364.     if (-e "$domainPathList{$domain}/local${domain}.dct") {
  365.         $do_toc = 1;
  366.     }
  367.  
  368.     &cleanDomainIndex($domain);
  369.  
  370.  
  371.     # performs all phases for books
  372.     #
  373.     if ($domain eq "bks") {
  374.  
  375.         system("/usr/bin/touch $op_info");
  376.         die "touch ($op_info) failed: $!\n" if ($?);
  377.  
  378.         my $bkopts = "";
  379.         if ($verbose == 1) {
  380.             $bkopts .= " -v ";
  381.         }
  382.         if ($force == 1) {
  383.             $bkopts .= " -force ";
  384.         }
  385.         my($rp) = ($root ne "/" ? $root : '');
  386.         my($r) = "${rp}/usr/share/Insight/library/SGI_bookshelves";
  387.  
  388.         system("$indexProg{$domain} $bkopts $r $output");
  389.         die "$indexProg{$domain}: unable to index books: $!\n" if ($?);
  390.  
  391.         system("/usr/bin/rm -f $op_info");
  392.         die "rm ($op_info) failed: $!\n" if ($?);
  393.     
  394.         system("/usr/bin/touch -amc $domain_dct");
  395.         die "touch ($domain_dct) failed: $!\n" if ($?);
  396.  
  397.     return;
  398.     }
  399.  
  400.  
  401.     my($extraFile)  = "$tmpdir/sgindex_extrafiles";
  402.     my($missingFile)= "$tmpdir/sgindex_missing";
  403.  
  404.     $v = "";
  405.     if($verbose == 1) {
  406.        $v = " -v ";
  407.     }
  408.  
  409.     # check for existing database, if not, we need to build a full one
  410.     
  411.     $m = "";
  412.     if(-e $domain_ttl) {
  413.        $m = " -db $domain_ttl -missing $missingFile ";
  414.     }
  415.  
  416.     # build list of dirs to look using ":" to separate them
  417.     #
  418.     my(@p, $spath) = "";
  419.     @p = split(/ /, $searchPath{$domain});
  420.     foreach $_ (@p) {
  421.        if ($_ ne "") {
  422.           if ($spath ne "") {
  423.              $spath = $spath.":".$_;
  424.           }
  425.           else {
  426.              $spath = $_;
  427.           }
  428.        }
  429.     }
  430.  
  431.     # run the alternate command to produce our list of extra/missing
  432.     #
  433.     $c = "$altProg{$domain} $m -extra $extraFile $v " .
  434.          "-regex $contentExpr{$domain} -path $spath ";
  435.     $c .= " -root $root " if ($root ne "/");
  436.     $c .= " 2>/dev/null";
  437.  
  438.     system($c);
  439.     die "Unable to create list of files for indexing: $!\n" if ($?);
  440.  
  441.     # sgmerge this to delete entries found to be missing from the hard disk
  442.     #
  443.     if(-e $domain_ttl && -e $missingFile && -s $missingFile) {
  444.  
  445.         if($verbose==1) {
  446.             $oldfiles = getFileLines($missingFile);
  447.             print "Removing $oldfiles extra documents from $domain index...\n";
  448.         }
  449.  
  450.         system("/usr/bin/touch $op_info");
  451.         die "touch ($op_info) failed: $!\n" if ($?);
  452.  
  453.         system("$timex sgmerge -x -b $domain_ttl -m $missingFile $output");
  454.         die "Failed to delete files from the $domain_ttl: $!\n" if ($?);
  455.  
  456.         print "Extra files removed from $domain_ttl index\n"
  457.                  unless ($verbose == 0);
  458.  
  459.         system("/usr/bin/rm -f $op_info");
  460.         die "rm ($op_info) failed: $!\n" if ($?);
  461.  
  462.         $do_toc = 1;
  463.     }
  464.  
  465.     # now add in the extra files to the local* database; or create full one
  466.     #
  467.     if (-e $extraFile && -s $extraFile) {
  468.  
  469.         if($verbose==1) {
  470.             $newfiles = getFileLines($extraFile);
  471.             print "Collecting words from $newfiles unindexed files...\n";
  472.         }
  473.  
  474.         $bLocal=0;
  475.         $db_ttl = $domain_ttl;
  476.         if(-e $domain_ttl) { 
  477.  
  478.            # create localfoo
  479.            $db_ttl =  $domain_ttl;
  480.            $db_ttl =~ s/$domain\.ttl/local$domain\.ttl/;
  481.            $bLocal = 1;
  482.         } else {
  483.            if($verbose==1) {
  484.                print "Forcing creation of new indices for $domain\n";
  485.            }
  486.         }
  487.  
  488.         if($bLocal == 0) {
  489.             system("/usr/bin/touch $op_info");
  490.             die "touch ($op_info) failed: $!\n" if ($?);
  491.         }
  492.         unless(&buildIndex($domain, $indexProg{$domain}, $extraFile, $db_ttl)){
  493.                print STDERR "Unable to create an index: $domain\n";
  494.         }
  495.         if($bLocal == 0) {
  496.            system("/usr/bin/rm -f $op_info");
  497.            die "rm ($op_info) failed: $!\n" if ($?);
  498.         }
  499.  
  500.         $do_toc = 1;
  501.  
  502.     } else {
  503.         print "No files to add to $domain index\n"
  504.                 unless ($verbose == 0);
  505.     }
  506.  
  507.     if ($do_toc == 1) {
  508.  
  509.         # create the toc LAST
  510.         #
  511.         &makeDomainTOC($domain);
  512.     }
  513.  
  514.  
  515.     # Update the last modified time of the dct even if we
  516.     # didn't need to modify the file just to "record" the
  517.     # last time we updated.  Needed for -instchk (the
  518.     # date of this file will be compared to the inst
  519.     # history file).
  520.     #
  521.     system("/usr/bin/touch -amc $domain_dct");
  522.     die "touch ($domain_dct) failed: $!\n" if ($?);
  523. }
  524.  
  525.  
  526. #---------------------------------------------------
  527. # instChkDomainUpdate($domain) # All if $domain=NULL 
  528. #
  529. sub instChkDomainUpdate {
  530.  
  531.     my($arg) = @_;
  532.  
  533.     my($hist) = "/var/inst/hist";
  534.     return unless(-e $hist);
  535.  
  536.     if ($arg ne '') {
  537.         @domainList = ("$arg");
  538.     }
  539.  
  540.     my($dct_mtime, $hist_mtime) = 0;
  541.     my(@fstat) = ();
  542.  
  543.     @fstat = stat("$hist");
  544.     $hist_mtime = ($fstat[9] + 0);
  545.  
  546.     foreach $domain (@domainList) {
  547.  
  548.     if( $domainPathList{$domain} eq '' ) {
  549.             next;
  550.     }
  551.  
  552.       $indexttl = "$domainPathList{$domain}/${domain}.dct";        
  553.  
  554.     if ((-e $indexttl) && (-w $indexttl)) { 
  555.  
  556.            # If the domain index files exists and it's older
  557.            # than the inst hist file, update the index.
  558.            #
  559.                @fstat = stat("$domainPathList{$domain}/${domain}.dct");
  560.                $dct_mtime = ($fstat[9] + 0);
  561.  
  562.                if ($hist_mtime > $dct_mtime) {
  563.            $startmsg = 
  564.             "infosearch $domain index is out of date: updating";
  565.            $endmsg   = "infosearch $domain index update completed";
  566.            system("logger -t sgindexAdmin \"$startmsg\"");        
  567.                    die "logger failed" if ($?);
  568.            &updateIndex($domain);
  569.            system("logger -t sgindexAdmin \"$endmsg\"");
  570.                    die "logger failed" if ($?);
  571.            }
  572.     }
  573.     }
  574. }
  575.  
  576.  
  577. #----------------------------------------------------
  578. # cleanDomainIndex($domainpath) # All if $domain=NULL 
  579. #
  580. sub cleanDomainIndex {
  581.  
  582.     my($arg) = @_;
  583.  
  584.     if ($arg eq ''){
  585.     foreach $domain (@domainList) {
  586.         &cleanAllIndexFiles($domain);
  587.     }
  588.     } else {
  589.     &cleanAllIndexFiles($arg);
  590.     }
  591. }
  592.  
  593.  
  594. #----------------------------
  595. # cleanAllIndexFiles($domain)
  596. #
  597. # Remove local files. If $force, remove all indices files
  598. #
  599. sub cleanAllIndexFiles {
  600.  
  601.     my($d) = @_;
  602.  
  603.     if ($domainPathList{$d} eq '') {
  604.         return;
  605.     }
  606.  
  607.     print "Removing local index files and table of contents for ${d}\n"
  608.     unless ($verbose == 0);
  609.  
  610.     $op = " ";
  611.     if ($clean_info == 1 || $force == 1) {
  612.        $op = "$domainPathList{$d}/_indexing";
  613.     }
  614.  
  615.     if ($force == 1) {
  616.     $localindex = "$domainPathList{$d}/*.??? " .
  617.                       "$domainPathList{$d}/*.html";
  618.     } else {
  619.     $localindex = "$domainPathList{$d}/local${d}.???";
  620.     }
  621.  
  622.     system("/usr/bin/rm -f $localindex $op");
  623.     die "rm index files failed:\n$localindex : $!\n" if ($?);
  624. }
  625.  
  626.  
  627. #-------------------------------------------------
  628. # makeDomainTOC($domainpath) # All if $domain=NULL
  629. #
  630. sub makeDomainTOC {
  631.  
  632.     my($arg) = @_;
  633.  
  634.     if ($arg eq '') {
  635.  
  636.         foreach $domain (@domainList) {
  637.  
  638.            if ($domainPathList{$domain} eq '') {
  639.                next;
  640.            }
  641.            $ttl = &domain2title($domain);
  642.  
  643.            $tocfiles = "$domainPathList{$domain}/*.html";
  644.            system("/usr/bin/rm -f $tocfiles");
  645.            die "rm toc files failed:\n$tocfiles : $!\n" if ($?);
  646.  
  647.            if (-e $ttl && -r $ttl) {
  648.               &makeBrowseTOC($domain);
  649.            } else {
  650.               print "\nCannot create table of contents for $domain\n"
  651.                         unless($verbose == 0 || $domain eq 'bks');
  652.            }
  653.         }
  654.  
  655.     } else {
  656.  
  657.         if ($domainPathList{$arg} eq '') {
  658.             return;
  659.         }
  660.         $ttl = &domain2title($arg);
  661.  
  662.         $tocfiles = "$domainPathList{$arg}/*.html";
  663.         system("/usr/bin/rm -f $tocfiles");
  664.         die "rm toc files failed:\n$tocfiles : $!\n" if ($?);
  665.  
  666.         if(-e $ttl && -r $ttl) {
  667.            &makeBrowseTOC($arg);
  668.         } else {
  669.            print "\nCannot create table of contents for $arg\n"
  670.                      unless($verbose == 0 || $domain eq 'bks');
  671.         }
  672.     }
  673. }
  674.  
  675.  
  676. #-----------------------
  677. # makeBrowseTOC($domain)
  678. #
  679. # Create a browsable index from the search indices
  680. #
  681. sub makeBrowseTOC {
  682.  
  683.     my($domain) = @_;
  684.     my($opts) = "";
  685.  
  686.     if ($tocProgramList{$domain} eq '') {
  687.        return;
  688.     }
  689.  
  690.     print "Building table of contents for $domain\n"
  691.         unless ($verbose == 0);
  692.  
  693.     $opts = &domain2title($domain);
  694.     if ($domain eq "man" && $instchk == 1) {
  695.     $opts = "$opts -whatis";
  696.     }
  697.  
  698.     $opts = $opts . " -coll $coll" if ($coll ne "");
  699.     system("$timex $tocProgramList{$domain} $opts ");
  700.     die "Failed to create a browsable index for $domain : $!\n" if ($?);
  701.  
  702.     print "Created a browsable index for $domain\n"
  703.         unless($verbose == 0);
  704. }
  705.  
  706.  
  707. #-----------------------------------------------------------------------
  708. # Boolean buildIndex($domain, $wordProg, $filesToIndex, $indexTitleFile) 
  709. #
  710. # $wordProg: the program used to create the word files
  711. #
  712. sub buildIndex {
  713.     
  714.     my($domain, $wordProg, $filesToIndex, $index_ttl) = @_;
  715.  
  716.     # Extrapolate the other index file names from the title file
  717.     #
  718.     $index_base = $index_ttl;
  719.     unless($index_base =~ s/\.ttl$//){
  720.     &tmpFileCleanup();
  721.     die "$index_ttl is not an index title file: $!\n";
  722.     }
  723.     
  724.     $index_dct        = "$index_base.dct";
  725.     $index_wrd        = "$index_base.wrd";
  726.     $index_tmpwrd   = "$index_base.wrd.tmp";
  727.  
  728.  
  729.     # Create the word file from the source content
  730.     # 
  731.     system("$timex $wordProg $filesToIndex > $index_wrd");
  732.     die "Error: Failed to make a word file for local files: $!\n" if ($?);
  733.     
  734.     system("/usr/bin/rm -f $filesToIndex");
  735.     die "rm ($filesToIndex) failed: $!\n" if ($?);
  736.     
  737.     unless($root eq "/"){
  738.     
  739.         $rootTrans = $root;
  740.     $rootTrans =~ s/\./\\\./g;
  741.     $rootTrans =~ s/\//\\\//g;
  742.     
  743.     my($trans) = "cat $index_wrd | " .
  744.         "sed -e \"s/$rootTrans//\" > $index_tmpwrd";
  745.  
  746.         system($trans);
  747.     die "Error: Failed to translate $index_wrd: $!\n" if ($?);
  748.  
  749.     &moveFile($index_tmpwrd,$index_wrd);  
  750.     }
  751.  
  752.  
  753.     # Create an index
  754.     # 
  755.     system("$timex sgdict $index_wrd $output");
  756.     die "Error: Failed to create a dictionary file: $!\n" if ($?);
  757.  
  758.     $invertcmd = "$timex sginverter -x 5000000 -t $index_ttl" .
  759.              " -d $index_dct $index_wrd $output";
  760.     system($invertcmd);
  761.     die "Error: Failed to create an inverted index: $!\n" if ($?);
  762.  
  763.  
  764.     # Cleanup
  765.     #
  766.     system("rm $index_wrd") unless ($keepwrd);
  767.     die "rm ($index_wrd) failed: $!\n" if ($?);
  768.  
  769.     return 1;
  770. }
  771.  
  772.  
  773. #----------------------
  774. # domain2title($domain)
  775. #
  776. sub domain2title {
  777.  
  778.     my($domain) = @_;
  779.     return("$domainPathList{$domain}/$domain.ttl");
  780. }
  781.  
  782. #---------------------------
  783. # domain2localtitle($domain)
  784. #
  785. sub domain2localtitle {
  786.  
  787.     my($domain) = @_;
  788.     return("$domainPathList{$domain}/local${domain}.ttl");
  789. }
  790.  
  791.  
  792. #----------------------
  793. # redirectedPath($path) 
  794. #
  795. # Return the path with the content root prepended
  796. #
  797. sub redirectedPath {
  798.  
  799.     my $arg = shift;
  800.     return($root ne "/" ? "$root$arg" : $arg);
  801. }
  802.  
  803. #-----------------
  804. # checkPath($path)
  805. #
  806. # Return 1 if the path is ok to process; avoid nastiness
  807. #
  808. sub checkPath {
  809.  
  810.     my($pth) = @_;
  811.  
  812.     if( ($pth cmp "/")   == 0 || ($pth cmp "//")  == 0 || ($pth cmp ".") == 0
  813.          ||
  814.         ($pth cmp "./")  == 0 || ($pth cmp "/.")  == 0
  815.          ||
  816.         ($pth cmp ".//") == 0 || ($pth cmp "//.") == 0 ) {
  817.          return 0;
  818.     }
  819.  
  820.     return 1;
  821. }
  822.  
  823. #------------------------
  824. # int getFileLines($file) 
  825. #
  826. # Return the number of lines in a file
  827. #
  828. sub getFileLines {
  829.  
  830.     my($file) = @_;
  831.     my($filelines) = 0;
  832.  
  833.     chop($filelines = `wc -l $file`);
  834.     $filelines =~ s/^\ *(\d+).*/$1/;
  835.  
  836.     return($filelines);
  837. }
  838.  
  839. #-------------------------------------------------
  840. # void moveFile(String $srcFile, String $destFile) 
  841. #
  842. # Move a file and report any errors
  843. #
  844. sub moveFile {
  845.  
  846.     my($srcFile,$destFile) = @_;
  847.  
  848.     system("/usr/bin/mv $srcFile $destFile");
  849.     die "mv ($srcFile $destFile) failed: $!\n" if ($?);
  850. }
  851.  
  852. #----------------------
  853. # void tmpFileCleanup() 
  854. #
  855. sub tmpFileCleanup {
  856.  
  857.     print "Removing temp files: $tmpdir/sgindex_*\n"
  858.     unless($verbose==0);
  859.  
  860.     system("/usr/bin/rm -f $tmpdir/sgindex_*");
  861.     die "rm ($tmpdir/sgindex_*) failed: $!\n" if ($?);
  862. }
  863.  
  864.  
  865.  
  866. # __END__ delimits the script from the data section
  867. # The following data is read in by the "DATA" filehandle.
  868. # This replaces the sgindexAdmin.config file.
  869.  
  870. __END__
  871.  
  872. DOMAIN     = man 
  873. TOCPROG    = /usr/lib/infosearch/bin/manTOC             
  874. INFOPATH   = $MANPATH else /usr/share/catman /usr/share/man /usr/catman /usr/man
  875. ALTPROG    = /usr/lib/infosearch/bin/manAdmin
  876. IDXPROG    = /usr/sbin/sgreader -q -a TITLE -t -i
  877. INFOREGEX  = '*\.*'
  878.  
  879. DOMAIN     = relnotes          
  880. TOCPROG    = /usr/lib/infosearch/bin/relnotesTOC                
  881. INFOPATH   = $RELNOTESPATH else /usr/relnotes
  882. ALTPROG    = /usr/lib/infosearch/bin/manAdmin
  883. IDXPROG    = /usr/lib/infosearch/bin/mkwordlist -i
  884. INFOREGEX  = '\( -name ch1.z -o -name ch01.z -o -name '*.gz' \)'
  885.  
  886. DOMAIN     = bks         
  887. TOCPROG    = 
  888. INFOPATH   = /usr/share/Insight/library/SGI_bookshelves
  889. ALTPROG    = 
  890. IDXPROG    = /usr/lib/infosearch/bin/booksAdmin
  891. INFOREGEX  = 
  892.